package com.jeeplus.modules.web.wx;

import com.alibaba.fastjson.JSON;
import com.jeeplus.core.web.BaseController;
import com.jeeplus.modules.web.entity.YJRoomUser;
import com.jeeplus.modules.web.entity.YjScoreRecord;
import com.jeeplus.modules.web.mapper.YjScoreRecordMapper;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author 十戒丶
 * @date 2021-02-07 19:33:49
 */
@Controller
@RequestMapping(value = "${adminPath}/wx/score_record")
public class YjScoreRecordBackController extends BaseController {
    @Autowired
    private YjScoreRecordMapper yjScoreRecordMapper;
    
    @RequiresPermissions("wx:score_record:list")
    @RequestMapping(value = {"list", ""})
    public String list(HttpServletRequest request, HttpServletResponse response, Model model) {
        model.addAttribute("yjRoomUser", new YJRoomUser());
        return "wx/score_record/list";
    }
    
    @RequiresPermissions(value = {"wx:score_record:view", "wx:score_record:add", "wx:score_record:edit"}, logical = Logical.OR)
    @RequestMapping(value = "form")
    public String form(YjScoreRecord yjScoreRecord, Model model) {
        final List<YjScoreRecord> list = yjScoreRecordMapper.findGamesCount(yjScoreRecord.getRoomFlag(), yjScoreRecord.getRoomUser());
        model.addAttribute("yjScoreRecord", yjScoreRecord);
        model.addAttribute("list", JSON.toJSONString(list));
        return "wx/score_record/form";
    }
}
